{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "from processing_utils import *\n",
    "import warnings\n",
    "warnings.filterwarnings('ignore')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_result = pd.read_excel('/home/yx/3090/project/P_prediction/Data/肺部并发症预测/baseline_result/baseline_text_time.xlsx')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "get_fig(df_result, 'f1', 0.5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.read_pickle('/home/yx/3090/project/P_prediction/Data/肺部并发症预测/data_time.pkl')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "text =  df.pop('术前诊断').astype(str)\n",
    "y = df.pop('肺部并发症').values\n",
    "df = fill_value(df, 'mean')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_train, df_test, y_train, y_test = time_split(df, y, 13904)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_results = []\n",
    "for model_name in ['LR', 'xgb', 'RF', 'lasso']:\n",
    "    if model_name == 'LR':\n",
    "        df_train = df_train[['年龄_术中', '氧饱和度', '近1月呼吸系统感染病史', '血红蛋白', '手术风险评估_手术部位', '手术时长（分钟）', '急诊/择期']]\n",
    "        df_test = df_test[['年龄_术中', '氧饱和度', '近1月呼吸系统感染病史', '血红蛋白', '手术风险评估_手术部位', '手术时长（分钟）', '急诊/择期']]\n",
    "    if model_name == 'LR' or model_name == 'lasso':\n",
    "        df_train = StandardScaler(df_train)\n",
    "        df_test = StandardScaler(df_test)\n",
    "    df_result = train(model_name, df_train, y_train, df_test, y_test, None, text, \"None\")\n",
    "    df_result['model'] = model_name\n",
    "    df_result['text'] = 'no'\n",
    "    df_results.append(df_result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "for model_name in [ 'LR', 'xgb', 'RF', 'lasso']:\n",
    "    if model_name == 'LR':\n",
    "            df_train = df_train[['年龄_术中', '氧饱和度', '近1月呼吸系统感染病史', '血红蛋白', '手术风险评估_手术部位', '手术时长（分钟）', '急诊/择期']]\n",
    "            df_test = df_test[['年龄_术中', '氧饱和度', '近1月呼吸系统感染病史', '血红蛋白', '手术风险评估_手术部位', '手术时长（分钟）', '急诊/择期']]\n",
    "    if model_name == 'LR' or model_name == 'lasso':\n",
    "        df_train = StandardScaler(df_train)\n",
    "        df_test = StandardScaler(df_test)\n",
    "    df_result = train(model_name, df_train, y_train, df_test, y_test, \"text\", text, \"None\")\n",
    "    df_result['model'] = model_name\n",
    "    df_result['text'] = 'yes'\n",
    "    df_results.append(df_result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_results_data = pd.concat(df_results)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_results_data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_results_data.to_excel('/home/yx/3090/project/P_prediction/Data/肺部并发症预测/baseline_result/baseline_text_time.xlsx')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.6.13 ('P_prediction')",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.13"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "676c8c2553a8289d770cd55f8a54cd76a7646969c2ee13a0fd2fdbb12048cb4a"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
